﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using NHibernate;

namespace BasicFrameworkDemo.IDAL
{
    public interface IRepository<TEntity>
        where TEntity : class, new()
    {
        /// <summary>
        /// Gets the entity queryable.
        /// </summary>
        /// <value>
        /// The entity queryable.
        /// </value>
        /// Creator:Li lei
        /// Creation Date:8/15/2011 10:26 AM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        IQueryable<TEntity> EntityQueryable { get; }

        /// <summary>
        /// Finds the by id.
        /// </summary>
        /// <param name="id">The id</param>
        /// <returns>
        /// The TEntity
        /// </returns>
        /// Creator:Li Lei
        /// Creation Date:8/11/2011 3:07 PM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        TEntity FindById(int id);

        /// <summary>
        /// Finds all.
        /// </summary>
        /// <returns>
        /// The list of TEntity
        /// </returns>
        /// Creator:Li Lei
        /// Creation Date:8/12/2011 10:30 AM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        IList<TEntity> FindAll();

        /// <summary>
        /// Finds the by expression.
        /// </summary>
        /// <param name="expression">The expression</param>
        /// <returns>
        /// The list of TEntity
        /// </returns>
        /// Creator:Li Lei
        /// Creation Date:8/18/2011 6:01 PM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        IList<TEntity> FindByExpression(Expression<Func<TEntity, bool>> expression);

        /// <summary>
        /// Finds the by expression.
        /// </summary>
        /// <param name="expression">The expression</param>
        /// <param name="currentPage">The currentPage</param>
        /// <param name="pageSize">The pageSize</param>
        /// <returns>
        /// The list of TEntity
        /// </returns>
        /// Creator:Li Lei
        /// Creation Date:11/15/2011 11:51 AM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        IList<TEntity> FindByExpression(Expression<Func<TEntity, bool>> expression, int currentPage, int pageSize);

        /// <summary>
        /// Finds the single by expression.
        /// </summary>
        /// <returns>
        /// The TEntity
        /// </returns>
        /// Creator:Li Lei
        /// Creation Date:8/18/2011 9:47 AM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        TEntity FindSingleByExpression();

        /// <summary>
        /// Finds the single by expression.
        /// </summary>
        /// <param name="expression">The expression</param>
        /// <returns>
        /// The TEntity
        /// </returns>
        /// Creator:Li Lei
        /// Creation Date:8/18/2011 9:47 AM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        TEntity FindSingleByExpression(Expression<Func<TEntity, bool>> expression);

        /// <summary>
        /// Finds the by SQL.
        /// </summary>
        /// <param name="hql">The sql</param>
        /// <returns>
        /// The list of TEntity
        /// </returns>
        /// Creator:Li Lei
        /// Creation Date:8/16/2011 1:09 PM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        IQuery FindIQueryByHql(string hql);

        /// <summary>
        /// Creates the TEntity
        /// </summary>
        /// <param name="entityList">The entityList</param>
        /// Creator:Li Lei
        /// Creation Date:8/11/2011 3:07 PM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        void Create(params TEntity[] entityList);

        /// <summary>
        /// The method will delete the list of entity of id.
        /// </summary>
        /// <param name="idList">The idList</param>
        /// Creator:Li Lei
        /// Creation Date:3/2/2012 10:06 AM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        void Remove(params int[] idList);

        /// <summary>
        /// Removes the TEntity
        /// </summary>
        /// <param name="entity">The entity</param>
        /// Creator:Li Lei
        /// Creation Date:8/11/2011 3:08 PM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        void Remove(TEntity entity);

        /// <summary>
        /// The method will delete the entity by expression
        /// </summary>
        /// <param name="expression">The expression</param>
        /// Creator:Li Lei
        /// Creation Date:3/2/2012 10:08 AM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        void Remove(Expression<Func<TEntity, bool>> expression);

        /// <summary>
        /// Updates the TEntity
        /// </summary>
        /// <param name="entityList">The entityList</param>
        /// Creator:Li Lei
        /// Creation Date:8/11/2011 3:08 PM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        void Update(params TEntity[] entityList);

        /// <summary>
        /// Saves the TEntity
        /// </summary>
        /// <param name="entityList">The entityList</param>
        /// Creator:Li Lei
        /// Creation Date:8/11/2011 3:08 PM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        void Save(params TEntity[] entityList);
    }
}
